package com.easywan.web.controller.users;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.easywan.core.JSPModelAndView;
import com.easywan.service.ArticleService;
import com.easywan.util.Utils;
import com.easywan.vo.Article;

@Controller
@RequestMapping("users")
public class ArticleControllerUsers {

	private static Logger logger = Logger.getLogger(ArticleControllerUsers.class);
	@Autowired
	private ArticleService articleService;
	@RequestMapping("article")
	public ModelAndView article_html(){
		return new JSPModelAndView("users/article");
	}
	@RequestMapping("article/apply")
	public void aricle_appy(HttpServletResponse res,Article article,HttpSession session){
		try{
			articleService.addArticle(article,Utils.getUserInfo(session));
			//System.out.println(article.getId());
			Utils.sendMsg(res, article.getId()+"");
		}catch(Exception e){
			e.printStackTrace();
			logger.error(e.getMessage());
			Utils.sendMsg(res, "0");
		}
	}
}
